<!-- 今日待提货页面 -->
<template>
    <view class="body">
        <Search @search="doSearch" />
        <scroll-view @scrolltolower="handleScroll" scroll-y="true" style="height: 100vh;">
            <view v-for="(item, index) in formList" :key="index" class="box">
                <SignItem :item="item" class="item" />
            </view>
        </scroll-view>
    </view>
</template>
  
<script setup lang='ts'>
import { ref } from "vue";
import dayjs from "dayjs";
import { OrderListType } from '@/type/index'
import { getWaitForReceiveList } from "@/@api/sign"; // sign的接口
import SignItem from '@/components/SignItem/index.vue'
import Search from '@/components/Search/index.vue'
import { useDidShow } from "@tarojs/taro";

import useUserStore from '@/store/user'
const store = useUserStore();

const loading = ref(false);
const formList = ref<OrderListType[]>([]);

const query = ref({
    pageNum: 1,
    pageSize: 15,
})

const params = ref({
    btcId: store.btsId,
    work: true,
    keywords: '',
    record: true,
    wxStatus: '', // 待确认1 待支付2 未发货3 运输中4 待签收5 已完成6
    isReceiving: '', // 待确认1 
    flag: '', // 待支付3
    startBillingTime: '',
    endBillingTime: '',
    // startBillingTime: dayjs().format('YYYY-MM-DD'), // llz
    // endBillingTime: dayjs().format('YYYY-MM-DD'), // llz
});

useDidShow(() => {
    query.value.pageNum = 1;
    formList.value = [];
    initList();
});


async function initList() {
    const res = await getWaitForReceiveList(query.value, params.value);
    if (res.data.code == 200) {
        formList.value = setStatusVal([...formList.value, ...res.data.rows])
        console.log(JSON.parse(JSON.stringify(formList.value)), '待提货列表数据');
        if (formList.value.length >= res.data.total) {
            loading.value = true;
        }
    }
}

function handleScroll() {
    if (!loading.value) {
        query.value.pageNum++;
        initList();
    }
}


// 添加状态标签
function setStatusVal(obj: OrderListType[]): OrderListType[] {
    let arr = obj.map((item: OrderListType) => {
        return {
            ...item,
            statusVal: '待提货'
        }
    })
    return arr
}

function doSearch(val: string) {
    query.value.pageNum = 1;
    formList.value = [];
    loading.value = false;
    params.value.keywords = val;
    initList();
}

</script> 
<style lang="scss">
.body {
    width: 100vw;
    height: 100vh;
    overflow: hidden;

    .box {
        overflow: auto;
        padding: 0 24rpx;
        box-sizing: border-box;
        background-color: #efeff4;
    }
}
</style>